*** This do file generates the output for tables 3, 4, 5, A9, A10, A11, and A12 using both sets of bootstrap replications 
*** Generated using seeds 123456 and 789012
*** Include results with just 2015 in the post period. But do NOT include these "only 2015" results in the overall averages calculations


*** Last updated 6/27/2024 - DH


set more off
capture log close

*** Set paths* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global logdir "$path/Logfiles"
global bootdir "$path/Estimates/Bootstrap/seed-123456"
global bootdir2 "$path/Estimates/Bootstrap/seed-789012"
global tabdir "$path/Estimates/Bootstrap/Tables"


log using "$logdir/generate-elasticities-and-ci-200-reps-no-2015-only-in-averages.log", replace




**** ESTIMATED COEFFICIENTS

* Set tempfiles for appending
tempfile ceplowskillnoswitch20192019
tempfile ceplowskillnoswitch20152019

tempfile ceplowskillswitch20192019
tempfile ceplowskillswitch20152015
tempfile ceplowskillswitch20152019

tempfile newlowskillswitch20192019

tempfile cepyoungnoswitch20192019
tempfile cepyoungnoswitch20152019

tempfile cepyoungswitch20192019
tempfile cepyoungswitch20152015
tempfile cepyoungswitch20152019

tempfile newyoungswitch20192019

tempfile overall

tempfile lowskillbaselinemeans
tempfile youngbaselinemeans

use "$bootdir/coef-emp-ow-mw-cep-lowskill-young-baseline-means.dta", clear

keep *_lowskill
rename *_lowskill *
save `lowskillbaselinemeans', replace

use "$bootdir/coef-emp-ow-mw-cep-lowskill-young-baseline-means.dta", clear

keep *_young
rename *_young *
save `youngbaselinemeans', replace 

* CEP Lowskill Switchers 2015-2015 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2015-2015.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20152015', replace


* CEP Lowskill No Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-noswitchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskillnoswitch20192019', replace

* CEP Lowskill No Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-noswitchers-2015-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskillnoswitch20152019', replace


* CEP Lowskill Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20192019', replace

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2015-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20152019', replace

* New Lowskill Switchers 2019 Post Period
use "$bootdir2/coef-emp-new-lowskill-switchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-new-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `newlowskillswitch20192019', replace


* CEP Lowskill No Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-young-noswitchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoungnoswitch20192019', replace

* CEP Young No Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-young-noswitchers-2015-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoungnoswitch20152019', replace


* CEP Young Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoungswitch20192019', replace

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2015-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoungswitch20152019', replace


* CEP Young Switchers 2015-2015 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2015-2015.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoungswitch20152015', replace

* New young Switchers 2019 Post Period
use "$bootdir2/coef-emp-new-young-switchers-2019-2019.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-new-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `newyoungswitch20192019', replace

* Append datsets together 
use `ceplowskillswitch20152019', replace
append using `ceplowskillswitch20152015'
append using `ceplowskillswitch20192019'

append using `ceplowskillnoswitch20152019'
append using `ceplowskillnoswitch20192019'

append using `newlowskillswitch20192019'

append using `cepyoungswitch20152019'
append using `cepyoungswitch20152015'
append using `cepyoungswitch20192019'

append using `cepyoungnoswitch20152019'
append using `cepyoungnoswitch20192019'

append using `newyoungswitch20192019'

keep if stat == "beta"


* Generate and append overall low-skill and young averages
preserve 

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

collapse emp_beta_all_allchange-emp_beta_cps_index ow_beta_allchange-mw_pre_index, by(sample)
gen stat = "beta"
save `overall', replace
restore

append using `overall'

replace policycat = "overall average" if policycat == ""


* Generate own wage and minimum wage elasticity estimates for each iteration

gen owe_all = (emp_beta_all_allchange/emp_pre_allchange)/(ow_beta_allchange/ow_pre_allchange)
gen owe_large = (emp_beta_all_large/emp_pre_large)/(ow_beta_large/ow_pre_large)
gen owe_small = (emp_beta_all_small/emp_pre_small)/(ow_beta_small/ow_pre_small)
gen owe_index = (emp_beta_all_index/emp_pre_index)/(ow_beta_index/ow_pre_index)

gen mwe_all = (emp_beta_all_allchange/emp_pre_allchange)/(mw_beta_allchange/mw_pre_allchange)
gen mwe_large = (emp_beta_all_large/emp_pre_large)/(mw_beta_large/mw_pre_large)
gen mwe_small = (emp_beta_all_small/emp_pre_small)/(mw_beta_small/mw_pre_small)
gen mwe_index = (emp_beta_all_index/emp_pre_index)/(mw_beta_index/mw_pre_index)

order policycat sample postmin postmax switchers, last


tab owe_small



* Export coefficients for employment effects with combined results for both ACS and CPS samples
export excel emp_beta_all_allchange-emp_beta_all_index policycat-switchers ///
using "$tabdir/Table-3-coef.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for employment effects with separate results for ACS and CPS samples
export excel emp_beta_acs_allchange-emp_beta_cps_index policycat-switchers ///
using "$tabdir/Table-A12-coef.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for wage effects
export excel ow_beta_allchange-mw_beta_index policycat-switchers ///
using "$tabdir/Table-A9-coef.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for elasticities
export excel owe_all-mwe_index emp_pre_allchange-mw_pre_index policycat-switchers ///
using "$tabdir/Table-5-coef.xlsx", firstrow(variables) nolabel keepcellfmt replace
*/




**** BOOTSTRAPPED CONFIDENCE INTERVALS

* Set tempfiles for appending from sets 1 and 2
tempfile ceplowskillnoswitch20192019
tempfile ceplowskillnoswitch20152019

tempfile ceplowskillswitch20152015
tempfile ceplowskillswitch20152019
tempfile ceplowskillswitch20192019

tempfile newlowskillswitch20192019

tempfile cepyoungnoswitch20192019
tempfile cepyoungnoswitch20152019

tempfile cepyoungswitch20152015
tempfile cepyoungswitch20152019
tempfile cepyoungswitch20192019

tempfile newyoungswitch20192019


tempfile ceplowskillnoswitch201920192
tempfile ceplowskillnoswitch201520192

tempfile ceplowskillswitch201520152
tempfile ceplowskillswitch201520192
tempfile ceplowskillswitch201920192

tempfile newlowskillswitch201920192

tempfile cepyoungnoswitch201920192
tempfile cepyoungnoswitch201520192

tempfile cepyoungswitch201520152
tempfile cepyoungswitch201520192
tempfile cepyoungswitch201920192

tempfile newyoungswitch201920192

tempfile loci
tempfile hici
tempfile loci_overall
tempfile hici_overall

tempfile ci
tempfile ci_overall

* Set tempfiles for CS 2017 analysis
tempfile ceplowskill20192019cs2017
tempfile ceplowskill20152015cs2017
tempfile ceplowskill20152019cs2017

tempfile cepyoung20192019cs2017
tempfile cepyoung20152015cs2017
tempfile cepyoung20152019cs2017

tempfile ceplowskill20192019cs20172
tempfile ceplowskill20152015cs20172
tempfile ceplowskill20152019cs20172

tempfile cepyoung20192019cs20172
tempfile cepyoung20152015cs20172
tempfile cepyoung20152019cs20172


tempfile lowskillbaselinemeans
tempfile youngbaselinemeans

use "$bootdir/boot-emp-ow-mw-cep-lowskill-young-baseline-means.dta", clear

keep iteration *_lowskill
rename *_lowskill *
save `lowskillbaselinemeans', replace

use "$bootdir/boot-emp-ow-mw-cep-lowskill-young-baseline-means.dta", clear

keep iteration *_young
rename *_young *
save `youngbaselinemeans', replace 

* CEP Lowskill No Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-noswitchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskillnoswitch20192019'

* CEP Lowskill No Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-noswitchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskillnoswitch20152019'

* CEP Lowskill Switchers 2015 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2015-2015.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20152015'

* CEP Lowskill Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20192019'

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskillswitch20152019'

* New Lowskill Switchers 2019 Post Period
use "$bootdir/boot-emp-new-lowskill-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-new-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `newlowskillswitch20192019'


* CEP Young No Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-young-noswitchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoungnoswitch20192019'

* CEP Young No Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-young-noswitchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoungnoswitch20152019'


* CEP Young Switchers 2015 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2015-2015.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoungswitch20152015'

* CEP Young Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoungswitch20192019'

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoungswitch20152019'

* New young Switchers 2019 Post Period
use "$bootdir/boot-emp-new-young-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-new-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `newyoungswitch20192019'





*** Set using seed 789012

* CEP Lowskill No Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-noswitchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `ceplowskillnoswitch201920192'

* CEP Lowskill No Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-noswitchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `ceplowskillnoswitch201520192'

* CEP Lowskill Switchers 2015 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2015-2015.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `ceplowskillswitch201520152'

* CEP Lowskill Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `ceplowskillswitch201920192'

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `ceplowskillswitch201520192'

* New Lowskill Switchers 2019 Post Period
use "$bootdir2/boot-emp-new-lowskill-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-new-lowskill-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen
replace iteration = 100 + iteration
save `newlowskillswitch201920192'


* CEP Young No Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-young-noswitchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-noswitchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `cepyoungnoswitch201920192'

* CEP Young No Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-young-noswitchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-noswitchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `cepyoungnoswitch201520192'

* CEP Young Switchers 2015 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2015-2015.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2015-2015.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `cepyoungswitch201520152'

* CEP Young Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `cepyoungswitch201920192'

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2015-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2015-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `cepyoungswitch201520192'

* New young Switchers 2019 Post Period
use "$bootdir2/boot-emp-new-young-switchers-2019-2019.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-new-young-switchers-2019-2019.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen
replace iteration = 100 + iteration
save `newyoungswitch201920192'



* Append all datsets together 
use `ceplowskillswitch20152019', replace
append using `ceplowskillswitch201520192'

append using `ceplowskillswitch20152015'
append using `ceplowskillswitch201520152'

append using `ceplowskillswitch20192019'
append using `ceplowskillswitch201920192'

append using `ceplowskillnoswitch20152019'
append using `ceplowskillnoswitch201520192'

append using `ceplowskillnoswitch20192019'
append using `ceplowskillnoswitch201920192'

append using `newlowskillswitch20192019'
append using `newlowskillswitch201920192'

append using `cepyoungswitch20152019'
append using `cepyoungswitch201520192'

append using `cepyoungswitch20152015'
append using `cepyoungswitch201520152'

append using `cepyoungswitch20192019'
append using `cepyoungswitch201920192'

append using `cepyoungnoswitch20152019'
append using `cepyoungnoswitch201520192'

append using `cepyoungnoswitch20192019'
append using `cepyoungnoswitch201920192'

append using `newyoungswitch20192019'
append using `newyoungswitch201920192'

* Generate seed for identifying which replication set we are working with
gen seed = 123456
replace seed = 789012  if inrange(iteration,101,200)

* Fix emp_beta_all_small
egen emp_beta_all_small_temp = rowmean(emp_beta_acs_small emp_beta_cps_small)
replace emp_beta_all_small = emp_beta_all_small_temp



* Generate own wage and minimum wage elasticity estimates for each iteration

gen owe_all = (emp_beta_all_allchange/emp_pre_allchange)/(ow_beta_allchange/ow_pre_allchange)
gen owe_large = (emp_beta_all_large/emp_pre_large)/(ow_beta_large/ow_pre_large)
gen owe_small = (emp_beta_all_small/emp_pre_small)/(ow_beta_small/ow_pre_small)
gen owe_index = (emp_beta_all_index/emp_pre_index)/(ow_beta_index/ow_pre_index)


gen mwe_all = (emp_beta_all_allchange/emp_pre_allchange)/(mw_beta_allchange/mw_pre_allchange)
gen mwe_large = (emp_beta_all_large/emp_pre_large)/(mw_beta_large/mw_pre_large)
gen mwe_small = (emp_beta_all_small/emp_pre_small)/(mw_beta_small/mw_pre_small)
gen mwe_index = (emp_beta_all_index/emp_pre_index)/(mw_beta_index/mw_pre_index)

order policycat sample postmin postmax switchers iteration, last


tab owe_small

*emp_beta_all_allchange ow_pre_allchange mw_pre_index owe_small mwe_index
preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution
gcollapse (p2.5) emp_beta_all_allchange-mwe_index, by(policycat sample postmin postmax switchers)

foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_loci

}
save `loci'
restore 


preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution
gcollapse (p97.5) emp_beta_all_allchange-mwe_index, by(policycat sample postmin postmax switchers)

foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_hici

}
save `hici'
restore 

preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution across all groups

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

gcollapse (p2.5) emp_beta_all_allchange-mwe_index, by(sample)
foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_loci

}
save `loci_overall'
restore 


preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution across all groups

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

gcollapse (p97.5) emp_beta_all_allchange-mwe_index, by(sample)
foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_hici

}
save `hici_overall'
restore

preserve
* Merge Lower and Upper CIs together
use `loci', clear
merge 1:1 policycat sample postmin postmax switchers using `hici', nogen
save `ci', replace
restore

cap drop _merge

preserve
* Merge Lower and Upper CIs together. Overall Averages
use `loci_overall', clear
merge 1:1 sample using `hici_overall', nogen
save `ci_overall', replace
restore 

cap drop _merge

use `ci', clear
append using `ci_overall'

replace policycat = "overall average" if policycat == ""

gsort sample policycat -switchers postmin

order emp_beta_all_allchange_* emp_beta_all_large_* emp_beta_all_small_* emp_beta_all_index_* emp_beta_acs_allchange_* emp_beta_acs_large_* emp_beta_acs_small_* emp_beta_acs_index_* emp_beta_cps_allchange_* emp_beta_cps_large_* emp_beta_cps_small_* emp_beta_cps_index_* ow_beta_allchange_* ow_beta_large_* ow_beta_small_* ow_beta_index_* mw_beta_allchange_* mw_beta_large_* mw_beta_small_* mw_beta_index_* emp_pre_allchange_* emp_pre_large_* emp_pre_small_* emp_pre_index_* ow_pre_allchange_* ow_pre_large_* ow_pre_small_* ow_pre_index_* mw_pre_allchange_* mw_pre_large_* mw_pre_small_* mw_pre_index_* owe_all_* owe_large_* owe_large_* owe_small_* owe_index_* mwe_all_* mwe_large_* mwe_small_* mwe_index_*, last




tostring emp_beta_all_allchange_loci-emp_beta_cps_index_hici, replace format(%15.3f) force


foreach var of varlist emp_beta_all_allchange_loci-emp_beta_cps_index_hici {
	replace `var' = usubinstr(`var', "0", "", 1) 
}

tostring ow_beta_allchange_loci-mwe_index_hici, replace format(%15.2f) force

* Generate confidence interval with comma and brackets
foreach var in emp_beta_all_allchange emp_beta_all_large emp_beta_all_small emp_beta_all_index emp_beta_acs_allchange emp_beta_acs_large emp_beta_acs_small emp_beta_acs_index emp_beta_cps_allchange emp_beta_cps_large emp_beta_cps_small emp_beta_cps_index ow_beta_allchange ow_beta_large ow_beta_small ow_beta_index mw_beta_allchange mw_beta_large mw_beta_small mw_beta_index emp_pre_allchange emp_pre_large emp_pre_small emp_pre_index ow_pre_allchange ow_pre_large ow_pre_small ow_pre_index mw_pre_allchange mw_pre_large mw_pre_small mw_pre_index owe_all owe_large owe_small owe_index mwe_all mwe_large mwe_small mwe_index {
	gen `var'_ci = "[" + `var'_loci + "," + `var'_hici + "]"
}

order policycat-switchers, first 

drop emp_beta_all_allchange_loci-mwe_index_hici

* Export confidence intervals for Table 3: employment effects with combined results for both ACS and CPS samples
export excel policycat-switchers emp_beta_all_allchange_ci-emp_beta_all_index_ci ///
using "$tabdir/Table-3-ci-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table A12: employment effects with separate results for ACS and CPS samples
export excel policycat-switchers emp_beta_acs_allchange_ci-emp_beta_cps_index_ci ///
using "$tabdir/Table-A12-ci-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table A9: wage effects
export excel policycat-switchers ow_beta_allchange_ci-mw_beta_index_ci ///
using "$tabdir/Table-A9-ci-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table 5: elasticities
preserve
keep if policycat == "overall average"
export excel sample owe_all_ci-mwe_all_ci ///
using "$tabdir/Table-5-ci-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace
restore







**** COEFFICIENTS AND CONFIDENCE INTERVALS CS 2017



* CEP Lowskill Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2019-2019-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskill20192019cs2017', replace

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2015-2019-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskill20152019cs2017', replace


* CEP Lowskill Switchers 2015-2015 Post Period
use "$bootdir2/coef-emp-cep-lowskill-switchers-2015-2015-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-lowskill-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `lowskillbaselinemeans', nogen

save `ceplowskill20152015cs2017', replace


* CEP Young Switchers 2019 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2019-2019-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoung20192019cs2017', replace

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2015-2019-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoung20152019cs2017', replace

* CEP Young Switchers 2015-2015 Post Period
use "$bootdir2/coef-emp-cep-young-switchers-2015-2015-cs2017.dta", clear
merge 1:1 _n using "$bootdir2/coef-ow-mw-cep-young-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 _n using `youngbaselinemeans', nogen

save `cepyoung20152015cs2017', replace



* Apppend files together
use  `ceplowskill20152019cs2017', replace
append using `ceplowskill20152015cs2017'
append using `ceplowskill20192019cs2017'

append using `cepyoung20152019cs2017'
append using `cepyoung20152015cs2017'
append using `cepyoung20192019cs2017'

keep if stat == "beta"


* Generate and append overall low-skill and young averages
preserve 

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

collapse emp_beta_all_allchange-emp_beta_cps_index ow_beta_allchange-mw_pre_index, by(sample)
gen stat = "beta"
save `overall', replace
restore

append using `overall'

replace policycat = "overall average" if policycat == ""


* Generate own wage and minimum wage elasticity estimates for each iteration

gen owe_all = (emp_beta_all_allchange/emp_pre_allchange)/(ow_beta_allchange/ow_pre_allchange)
gen owe_large = (emp_beta_all_large/emp_pre_large)/(ow_beta_large/ow_pre_large)
gen owe_small = (emp_beta_all_small/emp_pre_small)/(ow_beta_small/ow_pre_small)
gen owe_index = (emp_beta_all_index/emp_pre_index)/(ow_beta_index/ow_pre_index)

gen mwe_all = (emp_beta_all_allchange/emp_pre_allchange)/(mw_beta_allchange/mw_pre_allchange)
gen mwe_large = (emp_beta_all_large/emp_pre_large)/(mw_beta_large/mw_pre_large)
gen mwe_small = (emp_beta_all_small/emp_pre_small)/(mw_beta_small/mw_pre_small)
gen mwe_index = (emp_beta_all_index/emp_pre_index)/(mw_beta_index/mw_pre_index)

order policycat sample postmin postmax switchers, last


tab owe_small


keep if stat == "beta"


* Export coefficients for Table 4: employment effects for combined ACS and CPS samples using CS (2017) specifications
export excel emp_beta_all_allchange-emp_beta_all_index policycat-switchers ///
using "$tabdir/Table-4-coef-cs2017.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for Table A13: employment effects for separate ACS and CPS samples using CS (2017) specifications
export excel emp_beta_acs_allchange-emp_beta_cps_index policycat-switchers ///
using "$tabdir/Table-A13-coef-cs2017.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for Table A10: wage effects using CS (2017) specifications
export excel ow_beta_allchange-mw_beta_index policycat-switchers ///
using "$tabdir/Table-A10-coef-cs2017.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export coefficients for Table A11: elasticities using CS (2017) specifications
export excel owe_all-mwe_index emp_pre_allchange-mw_pre_index policycat-switchers ///
using "$tabdir/Table-A11-coef-cs2017.xlsx", firstrow(variables) nolabel keepcellfmt replace





************ CONFIDENCE INTERVALS


* CEP Lowskill Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2019-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20192019cs2017', replace

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2015-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20152019cs2017', replace


* CEP Lowskill Switchers 2015-2015 Post Period
use "$bootdir/boot-emp-cep-lowskill-switchers-2015-2015-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-lowskill-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20152015cs2017', replace


* CEP Young Switchers 2019 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2019-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index)
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20192019cs2017', replace

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2015-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20152019cs2017', replace


* CEP Young Switchers 2015 Post Period
use "$bootdir/boot-emp-cep-young-switchers-2015-2015-cs2017.dta", clear
merge 1:1 iteration using "$bootdir/boot-ow-mw-cep-young-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20152015cs2017', replace

*** Set using seed 789012

* CEP Lowskill Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2019-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20192019cs20172'

* CEP Lowskill Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2015-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20152019cs20172'


* CEP Lowskill Switchers 2015 Post Period
use "$bootdir2/boot-emp-cep-lowskill-switchers-2015-2015-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-lowskill-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `lowskillbaselinemeans', nogen

save `ceplowskill20152015cs20172'

* CEP Young Switchers 2019 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2019-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2019-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index)
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20192019cs20172'

* CEP Young Switchers 2015-2019 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2015-2019-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2015-2019-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20152019cs20172'


* CEP Young Switchers 2015-2015 Post Period
use "$bootdir2/boot-emp-cep-young-switchers-2015-2015-cs2017.dta", clear
merge 1:1 iteration using "$bootdir2/boot-ow-mw-cep-young-switchers-2015-2015-cs2017.dta", keepusing(ow_beta_allchange-mw_beta_index) nogen
merge 1:1 iteration using `youngbaselinemeans', nogen

save `cepyoung20152015cs20172'

* Apppend files together
use  `ceplowskill20152019cs2017', replace
append using `ceplowskill20152019cs20172'

append using `ceplowskill20152015cs2017'
append using `ceplowskill20152015cs20172'

append using `ceplowskill20192019cs2017'
append using `ceplowskill20192019cs20172'


append using `cepyoung20152019cs2017'
append using `cepyoung20152019cs20172'


append using `cepyoung20152015cs2017'
append using `cepyoung20152015cs20172'

append using `cepyoung20192019cs2017'
append using `cepyoung20192019cs20172'

egen emp_beta_all_small_temp = rowmean(emp_beta_acs_small emp_beta_cps_small)
replace emp_beta_all_small = emp_beta_all_small_temp
drop emp_beta_all_small_temp

* Generate own wage and minimum wage elasticity estimates for each iteration

gen owe_all = (emp_beta_all_allchange/emp_pre_allchange)/(ow_beta_allchange/ow_pre_allchange)
gen owe_large = (emp_beta_all_large/emp_pre_large)/(ow_beta_large/ow_pre_large)
gen owe_small = (emp_beta_all_small/emp_pre_small)/(ow_beta_small/ow_pre_small)
gen owe_index = (emp_beta_all_index/emp_pre_index)/(ow_beta_index/ow_pre_index)

gen mwe_all = (emp_beta_all_allchange/emp_pre_allchange)/(mw_beta_allchange/mw_pre_allchange)
gen mwe_large = (emp_beta_all_large/emp_pre_large)/(mw_beta_large/mw_pre_large)
gen mwe_small = (emp_beta_all_small/emp_pre_small)/(mw_beta_small/mw_pre_small)
gen mwe_index = (emp_beta_all_index/emp_pre_index)/(mw_beta_index/mw_pre_index)

drop spec

order policycat sample postmin postmax switchers iteration, last



preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution
gcollapse (p2.5) emp_beta_all_allchange-mwe_index, by(policycat sample postmin postmax switchers)

foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_loci

}
save `loci', replace
restore 


preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution
gcollapse (p97.5) emp_beta_all_allchange-mwe_index, by(policycat sample postmin postmax switchers)

foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_hici

}
save `hici', replace
restore 

preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution across all groups

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

gcollapse (p2.5) emp_beta_all_allchange-mwe_index, by(sample)
foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_loci

}
save `loci_overall', replace
restore 


preserve
* Collapse to generate upper and lower cis for each outcome from the bootstrapped distribution across all groups

* NOTE: We do NOT include the post period 2015 only results in the "overall averages" calculations

drop if postmax == 2015

gcollapse (p97.5) emp_beta_all_allchange-mwe_index, by(sample)
foreach var of varlist emp_beta_all_allchange-mwe_index {
	rename `var' `var'_hici

}
save `hici_overall', replace
restore

preserve
* Merge Lower and Upper CIs together
use `loci', clear
merge 1:1 policycat sample postmin postmax switchers using `hici', nogen
save `ci', replace
restore

cap drop _merge

preserve
* Merge Lower and Upper CIs together. Overall Averages
use `loci_overall', clear
merge 1:1 sample using `hici_overall', nogen
save `ci_overall', replace
restore 

cap drop _merge

use `ci', clear
append using `ci_overall'

replace policycat = "overall average" if policycat == ""

gsort sample policycat -switchers postmin

order emp_beta_all_allchange_* emp_beta_all_large_* emp_beta_all_small_* emp_beta_all_index_* emp_beta_acs_allchange_* emp_beta_acs_large_* emp_beta_acs_small_* emp_beta_acs_index_* emp_beta_cps_allchange_* emp_beta_cps_large_* emp_beta_cps_small_* emp_beta_cps_index_* ow_beta_allchange_* ow_beta_large_* ow_beta_small_* ow_beta_index_* mw_beta_allchange_* mw_beta_large_* mw_beta_small_* mw_beta_index_* emp_pre_allchange_* emp_pre_large_* emp_pre_small_* emp_pre_index_* ow_pre_allchange_* ow_pre_large_* ow_pre_small_* ow_pre_index_* mw_pre_allchange_* mw_pre_large_* mw_pre_small_* mw_pre_index_* owe_all_* owe_large_* owe_large_* owe_small_* owe_index_* mwe_all_* mwe_large_* mwe_small_* mwe_index_*, last


tostring emp_beta_all_allchange_loci-emp_beta_cps_index_hici, replace format(%15.3f) force


foreach var of varlist emp_beta_all_allchange_loci-emp_beta_cps_index_hici {
	replace `var' = usubinstr(`var', "0", "", 1) 
}

*Convert to string
tostring ow_beta_allchange_loci-mwe_index_hici, replace format(%15.2f) force 

* Generate confidence interval with comma and brackets
foreach var in emp_beta_all_allchange emp_beta_all_large emp_beta_all_small emp_beta_all_index emp_beta_acs_allchange emp_beta_acs_large emp_beta_acs_small emp_beta_acs_index emp_beta_cps_allchange emp_beta_cps_large emp_beta_cps_small emp_beta_cps_index ow_beta_allchange ow_beta_large ow_beta_small ow_beta_index mw_beta_allchange mw_beta_large mw_beta_small mw_beta_index emp_pre_allchange emp_pre_large emp_pre_small emp_pre_index ow_pre_allchange ow_pre_large ow_pre_small ow_pre_index mw_pre_allchange mw_pre_large mw_pre_small mw_pre_index owe_all owe_large owe_small owe_index mwe_all mwe_large mwe_small mwe_index {
	gen `var'_ci = "[" + `var'_loci + "," + `var'_hici + "]"
}

order policycat-switchers, first 

* Export confidence intervals for Table 4: employment effects with combined results for both ACS and CPS samples using CS (2017) specifications
export excel policycat-switchers emp_beta_all_allchange_ci-emp_beta_all_index_ci ///
using "$tabdir/Table-4-ci-cs2017-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table A13: employment effects with separate results for ACS and CPS samples using CS (2017) specifications
export excel policycat-switchers emp_beta_acs_allchange_ci-emp_beta_cps_index_ci ///
using "$tabdir/Table-A13-ci-cs2017-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table A10: wage effects using CS (2017) specifications
export excel policycat-switchers ow_beta_allchange_ci-mw_beta_index_ci ///
using "$tabdir/Table-A10-ci-cs2017-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace

* Export confidence intervals for Table A11: elasticities using CS (2017) specifications
preserve
keep if policycat == "overall average"
export excel sample owe_all_ci-mwe_index_ci ///
using "$tabdir/Table-A11-ci-cs2017-200-reps.xlsx", firstrow(variables) nolabel keepcellfmt replace
restore